package com.cci.kangdao.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.dto.request.GetSymptomMsgListRequest;
import com.cci.kangdao.dto.response.SymptomMsgList;
import com.cci.kangdao.dto.response.WorkOrderSymptomsDataResponse;
import com.cci.kangdao.model.WorkOrderSymptomsDataModel;
import com.cci.kangdao.model.condition.GetSymptomMsgListCondition;
import com.cci.kangdao.service.SymptomInfoService;
import com.cci.kangdao.utilTool.BeanUtils;
import com.cci.kangdao.utilTool.ParameterTool;

@Controller
public class SymptomInfoController {


	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private SymptomInfoService symptomInfoService;


	//获取症状集合
	@RequestMapping("/getSymptomList.aspx")
	public ModelAndView getSymptomList(HttpServletRequest request,
											 HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return symptomInfoService.getSymptomList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	
	
	@RequestMapping("/getSymptomMsgList.aspx")
	@ResponseBody
	public void getSymptomMsgList(GetSymptomMsgListRequest request,HttpServletResponse response){
		try{
			GetSymptomMsgListCondition condition = BeanUtils.convert(request, GetSymptomMsgListCondition.class);
			
			List<WorkOrderSymptomsDataModel> symptomMsgModelList = symptomInfoService.getSymptomMsgList(condition);
			
			List<WorkOrderSymptomsDataResponse> responseList = BeanUtils.convertList(symptomMsgModelList, WorkOrderSymptomsDataResponse.class);
			SymptomMsgList symptomMsgList = new SymptomMsgList(responseList);
			ParameterTool.writeSuccessResponse(response, symptomMsgList);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
	}

}
